package cn.itcast.nems.order.web.util;

import cn.hutool.core.collection.CollectionUtil;
import cn.itcast.nems.manager.util.CustomBeanUtil;
import cn.itcast.nems.order.dto.JournalDiscountDTO;
import cn.itcast.nems.order.web.vo.JournalDiscountEditVO;
import org.springframework.beans.BeanUtils;

/**
 * 业务凭单WEB层工具类
 *
 * @author ChangLu.Gao
 * @version v1.0
 * @program nems-server
 * @description
 * @date 2023/12/08 17:44
 */
public class BusinessApprovalFormWebUtil {

    /**
     * 优惠单保存/编辑数据转换
     *
     * @param source 源数据
     * @return cn.itcast.nems.order.dto.JournalDiscountDTO
     * @author 高昌露
     * @since 2023/12/8 17:46
     */
    public static JournalDiscountDTO convert(JournalDiscountEditVO source) {
        JournalDiscountDTO target = new JournalDiscountDTO();
        BeanUtils.copyProperties(source, target);
        if (CollectionUtil.isNotEmpty(source.getLineList())) {
            target.setLineList(
                    source.getLineList()
                            .stream()
                            .map(o -> CustomBeanUtil.copyProperties(o, new JournalDiscountDTO.JournalDiscountLineDTO()))
                            .toList()
            );
        }
        return target;
    }
}
